View Javadoc
1   package org.apache.maven.surefire.junitcore;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.List;
25  import java.util.concurrent.ExecutionException;
26  import java.util.concurrent.ExecutorService;
27  import java.util.concurrent.Executors;
28  import java.util.concurrent.Future;
29  
30  import org.junit.runners.model.RunnerScheduler;
31  
32  /**
33   * Since SUREFIRE 2.18 this class is deprecated.
34   * Please use {@link org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilder} instead.
35   *
36   * @author <a href="mailto:kristian@zenior.no">Kristian Rosenvold</a>
37   */
38  @Deprecated
39  public class AsynchronousRunner
40      implements RunnerScheduler
41  {
42      private final List<Future<Object>> futures = Collections.synchronizedList( new ArrayList<Future<Object>>() );
43  
44      private final ExecutorService fService;
45  
46      public AsynchronousRunner( ExecutorService fService )
47      {
48          this.fService = fService;
49      }
50  
51      public void schedule( final Runnable childStatement )
52      {
53          futures.add( fService.submit( Executors.callable( childStatement ) ) );
54      }
55  
56  
57      public void finished()
58      {
59          try
60          {
61              waitForCompletion();
62          }
63          catch ( ExecutionException e )
64          {
65              throw new RuntimeException( e );
66          }
67      }
68  
69      public void waitForCompletion()
70          throws ExecutionException
71      {
72          for ( Future<Object> each : futures )
73          {
74              try
75              {
76                  each.get();
77              }
78              catch ( InterruptedException e )
79              {
80                  throw new RuntimeException( e );
81              }
82          }
83      }
84  }